/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 徐海涛
 * Date: 2021-12-12
 * Time: 18:52
 */
class NameException extends RuntimeException  {
    //自定义异常一定要继承于一个异常类
    //Exception和RuntimeException一个是受查异常，一个非受查异常
    public NameException (String message) {
        super(message);
    }
}
class PasswordExcpetion extends RuntimeException {
    public PasswordExcpetion(String message) {
        super(message);
    }
}
public class TestDemo1 {
    private static final String name = "bit";
    private static final String password = "123";
    public static void login(String name,String password)throws NameException,PasswordExcpetion{//登录方法
        if(!TestDemo1.name.equals(name)){
            throw  new NameException("用户名错误");//
        }
        if(!TestDemo1.password.equals(password)){
            throw new PasswordExcpetion("密码错误");
        }
    }
    public static void main(String[] args) {
        try {
            login("bit","13");
        }catch (NameException e) {
            System.out.println("用户名错误");
        }catch (PasswordExcpetion e) {
            e.printStackTrace();
            System.out.println("密码错误");

        }finally {
            System.out.println("finally执行了");
        }
    }
}
